package edu.core.testapp.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Core_testapp implements EntryPoint {

	final Button btnSample = new Button("Sample");
	final Button btnProtect1 = new Button("protect01");
	final Button btnProtect2 = new Button("protect02");
	final Button btnProtect3 = new Button("protect03");
	final Button btnFiles = new Button("Files");
			
	final RootPanel mmc = RootPanel.get("mainMenuContainer");
	final RootPanel cc = RootPanel.get("clientContainer");
	
	final String mainMenuButtonStyleName = "mainMenuButton";
	
	private static Button curButton = null;

	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
		btnSample.addStyleName(mainMenuButtonStyleName);
		btnProtect1.addStyleName(mainMenuButtonStyleName);
		btnProtect2.addStyleName(mainMenuButtonStyleName);
		btnProtect3.addStyleName(mainMenuButtonStyleName);
		btnFiles.addStyleName(mainMenuButtonStyleName);
		
		mmc.add(btnSample);
		mmc.add(btnProtect1);
		mmc.add(btnProtect2);
		mmc.add(btnProtect3);
		mmc.add(btnFiles);
		
		btnSample.addClickHandler(new MainMenuButtonClickHandler(btnSample));
		btnProtect1.addClickHandler(new MainMenuButtonClickHandler(btnProtect1));
		btnProtect2.addClickHandler(new MainMenuButtonClickHandler(btnProtect2));
		btnProtect3.addClickHandler(new MainMenuButtonClickHandler(btnProtect3));
		btnFiles.addClickHandler(new MainMenuButtonClickHandler(btnFiles));
	}
	
	class MainMenuButtonClickHandler implements ClickHandler {
		
		private Button button;
		
		public MainMenuButtonClickHandler(Button btn) {
			this.button = btn;
		}

		@Override
		public void onClick(ClickEvent event) {
			// TODO Auto-generated method stub
			if (button == btnSample && curButton != btnSample) {
				cc.clear();
				cc.add(new SampleWidget());
			} else if (button == btnProtect1 && curButton != btnProtect1) {
				cc.clear();
				cc.add(new Protect01Widget());
			} else if (button == btnProtect2 && curButton != btnProtect2) {
				cc.clear();
				cc.add(new Protect02Widget());
			} else if (button == btnProtect3 && curButton != btnProtect3) {
				cc.clear();
				cc.add(new Protect03Widget());
			} else if (button == btnFiles && curButton != btnFiles) {
				cc.clear();
				cc.add(new StoredFileWidget());
			}
		}
		
	}
}
